package com.wzy.gmall.admin.aop;

import com.wzy.gmall.to.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
//统一处理异常
@RestControllerAdvice
public class GolbalExceptionHandler {
    @ExceptionHandler(NullPointerException.class)
    public Object handlerException(Exception e) {
        log.error("系统全局异常感知:信息:{}", e.getStackTrace());
        return new CommonResult().validateFailed("空指针异常了");
    }

    @ExceptionHandler(ArithmeticException.class)
    public Object handlerException2(Exception e) {
        log.error("系统全局异常感知:信息:{}", e.getStackTrace());
        return new CommonResult().validateFailed("数学计算异常");
    }


}
